//
//  UIApplication+utils.m
//  storeapp
//
//  Created by huangyi on 13-4-9.
//  Copyright (c) 2013年 ios. All rights reserved.
//

#import "UIApplication+utils.h"
#import "NSString+path.h"
#import "NSString+utils.h"
#import "NSData+hash.h"
#import "NSData+utils.h"

#define gitRevisionInfoKey "revision"

@implementation UIApplication (utils)

@end

NSString* appVersion(){
    NSDictionary *info=[NSBundle mainBundle].infoDictionary;
    NSString *version=info[@"CFBundleVersion"];
    return version;
}
NSString* appHash(){
    NSDictionary *info=[NSBundle mainBundle].infoDictionary;
    NSString *commit=info[NSStringFromCString(gitRevisionInfoKey)];
    if (commit==nil) {
        NSString *executable=info[@"CFBundleExecutable"];
        NSData *md5=file_digest_md5(executable.appPath);
        commit=[md5.hexString substringWithRange:NSMakeRange(0, 7)];
        commit=[NSString stringWithFormat:@"hex:%@",commit];
    }else{
        commit=[NSString stringWithFormat:@"rev:%@",commit];
    }
    return commit;
}
NSString* appBundleIdentifier(){
    NSDictionary *info=[NSBundle mainBundle].infoDictionary;
    NSString *version=info[@"CFBundleIdentifier"];
    return version;
}

